﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<AmazonCommon.Amazon.ECS.Item>" %>

<%@ Import Namespace="ShopzillaV1.Controllers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <% var reviewToShow = ViewData[VDConstants.ReviewToShow] as AmazonCommon.Amazon.ECS.Review; %>
    <div class="rightimage">
        <% Html.RenderPartial("ProductImage", Model.MediumImage); %>
    </div>
    <h3>
        <%=reviewToShow.Summary %>
    </h3>
    <b>
        <%=(reviewToShow.HelpfulVotes + " found it helpful.") %>
    </b>
    <h5>
        <%=(reviewToShow.Date + " - " + reviewToShow.Reviewer.Nickname) %>
    </h5>
    <p>
        Helpful Votes:<%=reviewToShow.HelpfulVotes %></p>
    <%
        if (reviewToShow.RatingSpecified)
        {
            Html.RenderPartial("StarRating", new AmazonCommon.DecimalWrapper(reviewToShow.Rating));
        }
    %>
    <a href='<%= Html.Encode(Model.DetailPageURL) %>' rel="nofollow">
        <img src="../../Content/images/shopnow.gif" alt="Buy It" /></a> <a href='<%= Html.Encode(Model.DetailPageURL) %>'
            rel="nofollow">
            <img src="../../Content/images/buynow.png" alt="Buy Now" /></a>
    <p>
        <%=reviewToShow.Content %>
    </p>
    <%= Html.ActionLink("View Details","ShowProductDetails",new {controller="Product",action="ShowProductDetails",id=Model.ASIN}) %>
    <br />
    More Reviews:
    <table>
        <tr>
            <th style="width: 100px">
                Rating Stars
            </th>
            <th>
                Helpful Votes
            </th>
            <th>
                Summary
            </th>
            <th>
                Content
            </th>
        </tr>
        <%  int counter = 0; %>
        <% foreach (var item in Model.CustomerReviews.Review)
           { %>
        <tr>
            <td>
                <% if (item.RatingSpecified)
                   {
                       Html.RenderPartial("StarRating", new AmazonCommon.DecimalWrapper(item.Rating));
                   } %>
            </td>
            <td>
                <%= Html.Encode(item.HelpfulVotes) + " of " +Html.Encode(item.TotalVotes) %>
            </td>
            <td>
                <%=Html.ActionLink(item.Summary, "Show", new
{
    controller = "Review",
    action = "Show", 
           id= Model.ASIN+"-" +"1" +"-" +counter.ToString()
})%>
            </td>
            <td>
                <%  int contentLimit = 100;
                    string trimmedContent = item.Content;
                    if (item.Content.Length > contentLimit)
                    {
                        trimmedContent = item.Content.Substring(0, contentLimit);
                        int whiteSpaceLastIndex = trimmedContent.LastIndexOf(' ');
                        trimmedContent = trimmedContent.Substring(0, whiteSpaceLastIndex);
                    } 
                %>
                <%=
                trimmedContent
                %>
            </td>
        </tr>
        <%
            counter++;
           } %>
    </table>
</asp:Content>
